package com.quan.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quan.admin.entity.SysRole;
import com.quan.admin.mapper.SysRoleMapper;
import com.quan.admin.service.SysRolePermissionService;
import com.quan.admin.service.SysRoleService;
import com.quan.commons.core.biz.support.MyBaseServiceImpl;
import com.quan.commons.core.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;


@Service
public class SysRoleServiceImpl extends MyBaseServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {

    @Autowired
	private SysRoleMapper mapper;

    @Autowired
    private SysRolePermissionService rolePermissionService;

	@Override
    public IPage<SysRole> selectMyPage(PageUtils pageUtils, SysRole entity) {
        Page<SysRole> page = new Page<SysRole>(pageUtils.getPage(), pageUtils.getLimit());

        // 排序
        super.handleSort(page, pageUtils);

        return this.mapper.selectMyPage(page, entity);
    }

    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        boolean falg = super.removeByIds(idList);

        idList.forEach(id -> {
            this.rolePermissionService.deleteByRoleId(id);
        });

        return falg;
    }

}